rmvnorm::rmvnorm(rowvec mu_in, mat sigma_in, icr_rands* inrands){
  //constructor
  rands = inrands;
  mu = mu_in;
  sigma = sigma_in;
  chol_sigma = trans(chol(sigma));

}

rowvec rmvnorm::draw(){
  //drawn N normal deviates, premultiply by cholesky factor, add mean

  //cout<<rands->randnorm()<<endl;
  //cout<<mu.n_cols<<endl;
  mat output;
  output.set_size(mu.n_rows, mu.n_cols);
  for(int i =0;i<(int)mu.n_cols;i++){
     output[i] = rands->randnorm();
  }
//chol_sigma.print("chol_sigma:");
  output = mu + output*chol_sigma;
  rowvec output0(output.n_elem);
  for(int i=0;i<(int) output.n_elem;i++){
    output0(i) = output(i);
  }
  return output0;
}

rmvnorm::~rmvnorm(){
  //destructor
}
